package cn.wolfcode.mq.listener;

import cn.wolfcode.common.exception.BusinessException;
import cn.wolfcode.domain.RefundVo;
import cn.wolfcode.service.IUsableIntegralService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: Ruomeng
 * @Date: 2025/2/25
 * @Description : shopseckill
 * @Version: 1.0
 */
@Slf4j
@Component
@RocketMQMessageListener(
        consumerGroup = "INTEGRAL_REFUND_TX_CONSUMER_GROUP",
        topic = "INTEGRAL_REFUND_TX_TOPIC"
)
public class IntegralRefundMessageListener implements RocketMQListener<RefundVo> {

    @Autowired
    private IUsableIntegralService usableIntegralService;


    @Override
    public void onMessage(RefundVo refundVo) {
        boolean res = usableIntegralService.doRefund(refundVo);
        log.info("[积分退款] 执行结果：{}，收到积分退款消息：{}", res, JSON.toJSONString(refundVo));
    }
}
